import React, {PropsWithChildren, useState} from 'react'
import {Text, View} from "@tarojs/components";
import styles from "./addEmployee.module.sass"
import EditEmployeeForm from "../components/EditEmployeeForm";
import {createEmployee} from "../apis/EmployeeApi";
import Taro from "@tarojs/taro";
import {Success} from "@nutui/icons-react-taro";
import {Button} from "@nutui/nutui-react-taro";
import MyNavigationBar from "../components/MyNavigationBar";

export interface AddEmployeeProps extends PropsWithChildren {

}

const AddEmployee: React.FC<AddEmployeeProps> = ({}) => {
    const [password,setPassword] = useState<string>()
    return <>
        <MyNavigationBar>添加人员</MyNavigationBar>
        {password?<>
            <View className={styles.container}>
                <Success color={"#fa2c19"} size={128}/>
                <Text style={{marginTop:24}}>注册成功</Text>
                <Text style={{marginTop:8}} onClick={()=>{
                    Taro.setClipboardData({
                        data: password!!
                    }).then(()=>{
                        Taro.showToast({
                            title: `密码已复制`,
                            duration: 1000,
                        })
                    });
                }}>密码为：{password}</Text>
                <Button block type={"primary"} style={{marginTop:40}} shape={"round"} onClick={()=>{
                    Taro.navigateBack()
                }}>返回</Button>
            </View>
        </>:<EditEmployeeForm onConfirm={async values => {
            let response = await createEmployee(values);
            setPassword(response.data.password)
        }} editPassword/>}
    </>
}

export default AddEmployee


